<--- %%NOBANNER%% --> validate.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| Validate a sas dataset variable to see if it matches a pattern     |
| it can distinguish;                                                |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|-----------<-- Start of Files or Arguements Needed-->---------------|
| Argument:                                                          |
|       Invar: the variable you want to verify;                      |
|       value: the value you want to check;                          |
|       outvar: the result of the verification;                      |
|-----------------<-- End of Arguements Needed-->--------------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example:                                                           |
| data test;                                                         |
|    w = 'abcde1';                                                   |
|     x = '1234567';                                                 |
|     a = '1234 567';                                                |
|     y = '123' ;                                                    |
|     z = 'a12' ;                                                    |
|    %validate ( invar=substr(w,1,3), value='abc', outvar=vw );      |
|     %validate ( invar=x, value=0123456789 , outvar=vx );           |
|     %validate ( invar=a, value='0123456789 ' , outvar=va );        |
|     %validate ( invar=y, value='0123456789' , outvar=vy );         |
|     %validate ( invar=z, value='0123456789' , outvar=vz );         |
| run;                                                               |
| Usage: %validate( invar= , value=, outvar= );                      |
\-------------------<-- End of Files Created-->---------------------*/
%macro validate( invar= , value=, outvar= );
/*---------------------------------------------\
| Author:  Duo Zhou;                           |
| Created: 9-6-2001 10:22pm;                   |
| Purpose: Validate a variable with a value to |
|          see if it is numeric or character.  |
\---------------------------------------------*/
if 0 ne verify ( &invar , &value ) then &outvar = 'invalid';
else &outvar = 'valid';
%mend validate;